#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>

int main()
{
  //int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  //int fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
  int fd = open("log.txt", O_RDONLY);
  if(fd < 0)
  {
    perror("open error");
    return -1;
  }
  dup2(fd,0);//输入重定向
  char line[64];
  while(1)
  {
    printf("请输入> ");
    if(fgets(line, sizeof(line), stdin) == NULL)
      break;
    printf("%s", line);
  }

  
  close(fd);
  return 0;
}
